package org.aplikator.client.descriptor;

import org.aplikator.client.widgets.FormWidget;
import org.aplikator.client.widgets.ReferenceFieldWidget;

import com.google.gwt.user.client.ui.Widget;

@SuppressWarnings("serial")
public class ReferenceFieldDTO implements WidgetDTO {

    private PropertyDTO<Integer> property;
    private ViewDTO view;
    private WidgetDTO child;

    @SuppressWarnings("unused")
    private ReferenceFieldDTO() {
    }

    public ReferenceFieldDTO(PropertyDTO<Integer> property, ViewDTO view, WidgetDTO child) {
        this.property = property;
        this.view = view;
        this.child = child;
    }

    public Widget getWidget(FormWidget form) {
        ReferenceFieldWidget field = new ReferenceFieldWidget(property.getLocalizedName(), view, child.getWidget(form));
        field.setProperty(property);
        form.registerDataField(field);
        return field;
    }

}
